<?php
/* ******************************
 *	transactions aJax actions
 * ******************************
 */
 
include('../../includes/classes/core.php');
include('../../includes/classes/log.class.php');

$log        = new log();

$action 	= $_REQUEST['act'];
$user_id	= $_COOKIE['USERID'];
$error 		= '';
$data 		= '';
	
switch ($action) {
	case 'get_edit_page':
		
		break;
    case 'get_list':
	    $count = $_REQUEST['count'];
	    $hidden = $_REQUEST['hidden'];
	    
        $rResult = mysql_query("SELECT 	   sale_transaction.id,
										   sale_transaction.start_date,
										   sale_transaction_status.description
								FROM 	   `sale_transaction`
								LEFT JOIN  sale_transaction_status ON sale_transaction.`status` = sale_transaction_status.id
								WHERE 	   sale_transaction.`status` = 2
								");
										
		$data = array(
			"aaData"	=> array()
		);
		
		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
				if($i == ($count - 1)){
					$row[] = '<input type="checkbox" name="check_' . $aRow[$hidden] . '" class="check" value="' . $aRow[$hidden] . '" />';
				}
			}
			$data['aaData'][] = $row;
		}
		
        break;
    case 'disable':
		$trans_id = $_REQUEST['id'];
		DisableProduct($trans_id);
		
        break;
    default:
       $error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);


/* ******************************
 *	transactions Functions
 * ******************************
 */

function DisableProduct($trans_id){
	
	 mysql_query("UPDATE sale_transaction
				SET     sale_transaction.`status` = 3
				WHERE   sale_transaction.id       = $trans_id ");
}

?>